package jdk5.misc;

import java.util.Collection;
import java.util.ArrayList;
import java.util.Iterator;

public class NewLoop{
       static public void oldPrint(Collection c){
           //old style for loop   
          for(Iterator i = c.iterator(); i.hasNext();){
                     Integer in = (Integer)i.next();
	  System.out.println(in);
             }
        }          
          //enhanced for loop
         static public void newPrint(Collection<Integer> c){
                  //enhanced for loop and unboxing
                  for(int i : c)     System.out.println(i);
         } 

       public static void main(String[] args){
               Collection c = new ArrayList();
               for(int i = 0; i < 5; i++) c.add(new Integer(i));
               oldPrint(c);

               Collection<Integer> ic = new ArrayList<Integer>();
               for(int i = 0; i < 5; i++) ic.add(i);   //autoboxing
               newPrint(c);
        } 
}